﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

namespace Articles_Ajax
{
    /// <summary>
    /// LoadArticles 的摘要说明
    /// </summary>
    public class LoadArticles : IHttpHandler
    {

        #region ProcessRequest
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            //读取文章ID
            String strArticleID = context.Request["article"].ToString();
            Int32 temp = 0;
            if (!Int32.TryParse(strArticleID, out temp))
            {
                context.Response.Write("参数传递-格式错误:" + strArticleID);
                return;
            }
            SqlParameter[] parm = {
                                      new SqlParameter("@AID",SqlDbType.Int)
                                  };
            parm[0].Value = Int32.Parse(strArticleID);
            System.Text.StringBuilder article = new System.Text.StringBuilder(9000);
            SqlDataReader sdr = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, CommandType.Text, "select AID,Title,Article from T_Articles T where T.AID=@AID", parm);
            while (sdr.Read())
            {
                article.Append(sdr["Title"].ToString());
                article.Append("-");
                article.Append(sdr["Article"].ToString());
            }
            sdr.Close();
            sdr.Dispose();
            //将 标题、文章 输出到客户端
            context.Response.Write(article.ToString());

            ////Shift+Alt + F10 接口自动完成
        }
        #endregion

        #region IsReusable
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
        #endregion

    }
}